﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MySql.Data.MySqlClient;
using System.Configuration;
using System.Data.SqlClient;

namespace Framework_Tool
{

    public partial class StaffUpdate : Page
    {
        MainWindow main;

        public StaffUpdate()
        {
            InitializeComponent();
            stfIDUpdateCmbx.Items.Clear();
            Database.FindStaffID_Update(this);
        }

        private void viewStaff_Click(object sender, RoutedEventArgs e)
        {
            StaffView stfViewWindow = new StaffView();
            stfViewWindow.Content = null;
            mainContent.Children.Add(stfViewWindow.mainContent);
        }

        private void addStaff_Click(object sender, RoutedEventArgs e)
        {
            StaffAdd stfAddWindow = new StaffAdd(main);
            stfAddWindow.Content = null;
            mainContent.Children.Add(stfAddWindow.mainContent);
        }

        private void deleteStaff_Click(object sender, RoutedEventArgs e)
        {
            StaffDelete stfDeleteWindow = new StaffDelete();
            stfDeleteWindow.Content = null;
            mainContent.Children.Add(stfDeleteWindow.mainContent);
        }

        private void searchStaff_Click(object sender, RoutedEventArgs e)
        {
            StaffSearch stfSearchWindow = new StaffSearch();
            stfSearchWindow.Content = null;
            mainContent.Children.Add(stfSearchWindow.mainContent);
        }

        private void stfIDUpdate_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Database.populateFields_StfUpdate(this);
        }

        private void mainContent_Loaded(object sender, RoutedEventArgs e)
        {
            viewStaff.FontWeight = FontWeights.Normal;
            addStaff.FontWeight = FontWeights.Normal;
            updateStaff.FontWeight = FontWeights.ExtraBold;
            deleteStaff.FontWeight = FontWeights.Normal;
            searchStaff.FontWeight = FontWeights.Normal;
        }

        private void stfUpdate_Click(object sender, RoutedEventArgs e)
        {
            Database.IsValidStfEmail_Update(this);
            Database.UpdateStaff(this);
        }

        private void cancelStfUpdate_Click_1(object sender, RoutedEventArgs e)
        {
            stfIDUpdateCmbx.SelectedValue = null;
            
            stfFNameTxt.Text = null;
            stfSurnameTxt.Text = null;
            stfALine1Txt.Text = null;
            stfALine2Txt.Text = null;
            stfCityTxt.Text = null;
            stfCountyTxt.Text = null;
            stfPostcodeTxt.Text = null;
            stfJobTitleTxt.Text = null;
            stfTelNoTxt.Text = null;
            stfEmailTxt.Text = null;
            stfPasswordUpdateTxt.Password = null;
            stfPassword1UpdateTxt.Password = null;

            matchStfPasswordLbl.Visibility = Visibility.Hidden;
            validStfPasswordLbl.Visibility = Visibility.Hidden;
            stfEmailValidationLbl.Visibility = Visibility.Hidden;
        }

        private void stfEmailTxt_LostFocus_1(object sender, RoutedEventArgs e)
        {
            Database.IsValidStfEmail_Update(this);
        }

        private void stfPasswordUpdateTxt_LostFocus_1(object sender, RoutedEventArgs e)
        {
            Database.ValidatePassword_StfUpdate(this);
        }

        private void stfPassword1UpdateTxt_LostFocus_1(object sender, RoutedEventArgs e)
        {
            Database.ComparePasswords_stfUpdate(this);
        }

    }
}
